<?php
  
  function tender_form_validation($form) {

    $stat = new set_static_variable();
    //print '<pre>'; print_r($form); print'</pre>';

    //Concerned dept validation
	//chk_concerned_dept($form['field_ten_department']); 
   //tittle validation
   //check_title_duplication($form['title'], $form['type']['#value'],$form['field_ten_department'], 'field_ten_department', $stat->get_nid());
    $stat->set_nid(0);
    chkbadchar($form['title']['#value'], $form['title']['#title'], 'title'); 
	
	// maximum length validation for Title and Description Field
    maxlength_validation($form['title']['#value'], 255, $form['title']['#title'], 'title');
	
	// minimum length charcter   
  	minilength_validation($form['title']['#value'], 5, $form['title']['#title'], 'title');
  	minilength_validation($form['field_ten_keywordc']['und'][0]['value']['#value'], 5, $form['field_ten_keywordc']['und'][0]['value']['#title'],'field_ten_keywordc');
	
	
	//Bad character validations
	chkbadchar($form['title']['#value'], $form['title']['#title'], 'title');
    chkbadchar($form['field_ten_keywordc']['und'][0]['value']['#value'], $form['field_ten_keywordc']['und'][0]['value']['#title'],'field_ten_keywordc'); 

    
    // Tender Reference number validation
    //check_integer($form['field_ten_refno'][0]['value']['#value'], $form['field_ten_refno']['#title'],                                                                           $form['field_ten_refno'][0]['#field_name']);

    //DIPR number validaiton  
    
   //check_integer($form['field_ten_dipr'][0]['value']['#value'], $form['field_ten_dipr']['#title'],                                                                 $form['field_ten_dipr'][0]['#field_name']);
   
   
   // Tender Reference number And DIPR number
    maxlength_validation($form['field_ten_refno'][0]['value']['#value'], 255, $form['field_ten_refno']['#title'], 'field_ten_refno');
	maxlength_validation($form['field_ten_dipr'][0]['value']['#value'], 255, $form['field_ten_dipr']['#title'], 'field_ten_dipr');
	maxlength_validation($form['field_ten_keywordc'][0]['value']['#value'], 255, $form['field_ten_keywordc']['#title'], 'field_ten_keywordc');
  //date validtion
	
	//check_scheduler_date_expire($form['scheduler_settings']['unpublish_on']['date']['#value'],'Valid upto');
    //check_date_expire($form['field_ten_annosment_date'][0]['value']['date']['#value'],$form['field_ten_annosment_date']['#title']);
	
    //$ann_date = $form['field_ten_annosment_date'][0]['value']['date']['#value'];
    //$last_date = $form['field_ten_lastdate'][0]['value']['date']['#value'];
   // $open_date = $form['field_ten_openingdate'][0]['value']['date']['#value']; 

    /*$flag = 0;
    $flag += check_date_expire($form['field_ten_annosment_date'],$ann_date);
    $flag += check_date_expire($form['field_ten_lastdate'],$last_date);
    $flag += check_date_expire($form['field_ten_openingdate'],$open_date);*/
    
   
   /* if ($ann_date != "" && $last_date != "" && dateDiff("-", $last_date, $ann_date) < 0 && $flag == 0) {
      form_set_error('field_ten_annosment_date', t('%expire_date is cannot be Lower than %start date', 
                                                    array('%expire_date' => $form['field_ten_lastdate']['#title'], 
                                                          '%start' => $form['field_ten_annosment_date']['#title'])));
      form_set_error('field_ten_lastdate',' ');
      //$flag += 1;
    }
	
    if ($last_date != "" && $open_date != "" && dateDiff("-", $open_date, $last_date) < 0 && $flag == 0) {
      form_set_error('field_ten_lastdate', t('%expire_date cannot be Lower than %start date', 
                                                    array('%expire_date' => $form['field_ten_openingdate']['#title'], 
                                                          '%start' => $form['field_ten_lastdate']['#title'])));
      form_set_error('field_ten_openingdate',' ');
    }
	$today = date("d-m-Y");
	if ($ann_date != "" && dateDiff("-", $ann_date, $today) < 0 && $flag == 0) {
      form_set_error('field_ten_annosment_date', t('%expire_date cannot be Lower %start date', 
                                                    array('%expire_date' => $form['field_ten_annosment_date']['#title'], 
                                                          '%start' => $today)));
      form_set_error('field_ten_openingdate',' ');
    }*/
   

  	// Availability Of Tender validation
   /* $form_type = $form['field_ten_notice'];
    
	if ($form_type['value']['#value'] == 'Online Available') {
	
	$download = $form_type['value']['#value'] == 'Downloadable';
	$down =  $form['field_ten_available'][0]['#value']['filename']; 
	if(!empty($down) ) {
	
	form_set_error('field_ten_available', t('Please remove Download pdf', array(
													   '%name' => $form['field_ten_available']['#title'])));
	}
      
	  $reference_url = $form['field_ten_downladable'][0]['value']['#value'];
	  $reference_url = url_validation($reference_url);
	  
     if(isURL($reference_url) == 0 && $reference_url != '') {
      form_set_error('field_ten_downladable', t('Not a valid URL given in %name field', array(
                                                   '%name' => $form['field_ten_downladable']['#title'])));    
    }
    elseif ($reference_url == '') {
      form_set_error('field_ten_downladable', t(' %name field is required', array(
                                                   '%name' => $form['field_ten_downladable']['#title'])));
    } 
  }
	elseif ($form_type['value']['#value'] == 'Downloadble') {
	
	$online = $form_type['value']['#value'] == 'Online Available';
	$online = '';
	
    // Validating the file size   
    $field_obj = $form['field_ten_available']; 
	$file_allowed_obj = $form['field_form_allowedfiletype'];
    file_upload_validation($field_obj, $file_allowed_obj, 'field_ten_available');  
  } */

     
 
}

  
 
